package math;

/**
 *
 * @author Lei
 */
public class GetNumberOfTrailingZerosInNFactorial {

    public static int getNumberOfTrailingZerosInNFactorial(int N) {
        int count = 0;
        if (N < 0) {
            System.out.println("Factorial is not defined for < 0");
            return 0;
        }
        for (int i = 5; N / i > 0; i *= 5) {
            count += N / i;
        }
        return count;
    }

    public static void main(String[] args) {

        System.out.println("the trailing zeros in 26! : " + GetNumberOfTrailingZerosInNFactorial.getNumberOfTrailingZerosInNFactorial(26));

    }
}
